# Author    :Dun_Hz
# Time      :2024/3/15 11:14
# 二分查找，找有序列表的指定值

def BinarySearch(li, key):
    min = 0
    max = len(li) - 1
    if key in li:
        while True:
            #得到中位数
            mid = (min+max)//2
            if li[mid]>key:
                max = mid
            elif li[mid]<key:
                min = mid+1
            elif li[mid]==key:
                print(str(key)+'在数组里第'+str(mid+1)+'个位置')
                return li[mid]
    else:
        print('没有这个数字')

if __name__ =='__main__':
    li = [1,6,8,13,32,66,83,92]
    while True:
        key = input("请输入你要查找的数字：")
        if key == ' ':
            print('终止查询')
            break
        else:
            BinarySearch(li,int(key))